![]() |
![]() | ||
![]() | |||
![]() ![]() ![]() ![]()
Layout Manager |
└∩δσ≥ FormLayout┬ εΩφσ α∩δσ≥α FormLayout (≡Φ±. 2) ∞√ ≡α±∩εδεµΦδΦ ≥σ µσ ±α∞√σ ε≡παφ√ ≤∩≡αΓδσφΦ , Ωε≥ε≡√σ ß√δΦ Φ±∩εδⁿτεΓαφ√ Γ ∩≡σΣ√Σ≤∙σ∞ α∩δσ≥σ FormDemo. ╬ΣφαΩε Σδ ≤ΩαταφΦ ±∩ε±εßα ≡ατ∞σ∙σφΦ Ωε∞∩εφσφ≥ ∞√ Γ√∩εδφΦδΦ φα±≥≡εΘΩ≤ ±Φ±≥σ∞√ Layout Manager, Γ√ß≡αΓ ≡σµΦ∞ GridLayout.
╚ ⌡ε≥ ∩εΩα σ∙σ Γφσ°φΦΘ ΓΦΣ φα°σΘ ⌠ε≡∞√ ε±≥αΓδ σ≥ µσδα≥ⁿ δ≤≈°σπε, ≡α±∩εδεµσφΦσ ε≥Σσδⁿφ√⌡ Ωε∞∩εφσφ≥ φσ Φτ∞σφ σ≥± ∩≡Φ Φτ∞σφσφΦΦ ≡ατ∞σ≡εΓ εΩφα α∩δσ≥α. ╧≡εßδσ∞α ταΩδ■≈ασ≥± Γ ≥ε∞, ≈≥ε Γ ≡σµΦ∞σ GridLayout φσ ≤Σασ≥± ≤∩≡αΓδ ≥ⁿ ≡ατ∞σ≡α∞Φ Ωε∞∩εφσφ≥. ─δ ≤±≥≡αφσφΦ ²≥επε φσΣε±≥α≥Ωα ±δσΣ≤σ≥ Φ±∩εδⁿτεΓα≥ⁿ ≡σµΦ∞ GridBagLayout. ╥αΩ ΩαΩ ²≥ε≥ ≡σµΦ∞ ±δεµσφ Σδ Φ±∩εδⁿτεΓαφΦ ßστ ΓΦτ≤αδⁿφεπε ∩≡εσΩ≥Φ≡εΓαφΦ , ∞√ ε≥δεµΦ∞ ΣαδⁿφσΘ°σσ ±εΓσ≡°σφ±≥εΓεΓαφΦσ φα°σΘ ⌠ε≡∞√ Σε ≥σ⌡ ∩ε≡, ∩εΩα φσ ταΘ∞σ∞± Φτ≤≈σφΦσ∞ ±εε≥Γσ≥±≥Γ≤■∙Φ⌡ ±≡σΣ±≥Γ Java WorkShop. ╚±⌡εΣφ√Θ ≥σΩ±≥ α∩δσ≥α FormLayout╚±⌡εΣφ√Θ ≥σΩ±≥ α∩δσ≥α FormLayout ∩≡αΩ≥Φ≈σ±ΩΦ ∩εΓ≥ε≡ σ≥ Φ±⌡εΣφ√Θ ≥σΩ±≥ α∩δσ≥α FormDemo, ≡α±±∞ε≥≡σφφ√Θ Γ φα°σΘ ∩≡σΣ√Σ≤∙σΘ ±≥α≥ⁿσ. ┼ΣΦφ±≥Γσφφεσ ε≥δΦ≈Φσ ταΩδ■≈ασ≥± Γ ≥ε∞, ≈≥ε Γ ∞σ≥εΣσ init ∞√ Γ√∩εδφΦδΦ φα±≥≡εΘΩ≤ ±Φ±≥σ∞√ Layout Manager, ≤±≥αφεΓΦΓ ≡σµΦ∞ GridLayout: public void init() { setLayout(new GridLayout(4, 3)); . . . } ╟Σσ±ⁿ Σδ ≡ατ∞σ∙σφΦ Ωε∞∩εφσφ≥ Γ εΩφσ α∩δσ≥α ±ετΣασ≥± ≥αßδΦ÷α Φτ ≈σ≥√≡σ⌡ ±≥≡εΩ Φ ≥≡σ⌡ ±≥εδß÷εΓ. ╧εδφ√Θ Φ±⌡εΣφ√Θ ≥σΩ±≥ α∩δσ≥α FormLayout Γ√ φαΘΣσ≥σ Γ δΦ±≥Φφπσ 1. ╦Φ±≥Φφπ 1. ╘αΘδ FormLayout.java import java.applet.Applet; import java.awt.*; import java.util.*; public class FormLayout extends Applet { Button btReady; Checkbox chbox1; Checkbox chbox2; CheckboxGroup grRadio; Checkbox rd1; Checkbox rd2; Checkbox rd3; Choice ch1; Label lbFirstName; Label lbSecondName; TextField txtFirstName; TextField txtSecondName; TextArea txta; public void init() { setLayout(new GridLayout(4, 3)); chbox1 = new Checkbox("First"); add(chbox1); lbFirstName = new Label( "Enter your first name:"); add(lbFirstName); txtFirstName = new TextField(" ", 30); add(txtFirstName); chbox2 = new Checkbox("Second"); add(chbox2); lbSecondName = new Label( "Enter your second name:"); add(lbSecondName); txtSecondName = new TextField(" ", 30); add(txtSecondName); grRadio = new CheckboxGroup(); rd1 = new Checkbox("Mode 1", grRadio, true); rd2 = new Checkbox("Mode 2", grRadio, false); rd3 = new Checkbox("Mode 3", grRadio, false); add(rd1); add(rd2); add(rd3); ch1 = new Choice(); ch1.addItem("White"); ch1.addItem("Green"); ch1.addItem("Yellow"); add(ch1); setBackground(Color.yellow); lbFirstName.setBackground( Color.yellow); lbSecondName.setBackground( Color.yellow); rd1.setBackground(Color.yellow); rd2.setBackground(Color.yellow); rd3.setBackground(Color.yellow); chbox1.setBackground(Color.yellow); chbox2.setBackground(Color.yellow); txta = new TextArea("", 6, 45); add(txta); txta.setBackground(Color.white); btReady = new Button("Ready"); add(btReady); } public String getAppletInfo() { return "Name: FormDemo"; } public void paint(Graphics g) { Dimension dimAppWndDimension = getSize(); g.setColor(Color.black); g.drawRect(0, 0, dimAppWndDimension.width - 1, dimAppWndDimension.height - 1); } public boolean action(Event evt, Object obj) { Button btn; String str1, str2; if(evt.target instanceof Button) { if(evt.target.equals(btReady)) { btn = (Button)evt.target; str1 = txtFirstName.getText(); str2 = txtSecondName.getText(); if(chbox1.getState()) txta.append(str1); if(chbox2.getState()) txta.append(str2); if(rd1.getState()) txta.append("\nMode 1\n"); if(rd2.getState()) txta.append("\nMode 2\n"); if(rd3.getState()) txta.append("\nMode 3\n"); } else { return false; } return true; } else if(evt.target instanceof Choice) { if(evt.target.equals(ch1)) { if(ch1.getSelectedIndex() == 0) txta.setBackground(Color.white); if(ch1.getSelectedIndex() == 1) txta.setBackground(Color.green); if(ch1.getSelectedIndex() == 2) txta.setBackground(Color.yellow); } } return false; } } ╚±⌡εΣφ√Θ ≥σΩ±≥ ΣεΩ≤∞σφ≥α HTML, ±ετΣαφφ√Θ Σδ φα°σπε α∩δσ≥α ±Φ±≥σ∞εΘ Java WorkShop, ∩≡σΣ±≥αΓδσφ Γ δΦ±≥Φφπσ 2. ╦Φ±≥Φφπ 2. ╘αΘδ FormLayout.tmp.html |